#!/usr/bin/env bash

if [[ "${BUILDKITE_STEP_KEY}" == "lint-version" ]] && [[ "${BUILDKITE_BRANCH}" != "master" ]] && [[ "${CHART_CHANGES}" == "true" ]]; then
  # Buildkite doesn't fetch the master branch when when the commit is not on master so we need to do this for CT.
  echo "--- :fork: Fetching repository branch master"

  git fetch --verbose --prune origin master
fi

if [[ "${BUILDKITE_STEP_KEY}" == "index" ]] && [[ "${BUILDKITE_BRANCH}" == "master" ]]; then
  # Buildkite doesn't fetch the gh-pages branch when when the commit is against master so we need to do this for CR.
  echo "--- :fork: Fetching repository branch gh-pages"

  git fetch --verbose --prune origin gh-pages
fi

if [[ "${BUILDKITE_STEP_KEY}" == "index" ]] || [[ "${BUILDKITE_STEP_KEY}" == "upload" ]]; then
  echo "--- :sparkles: Setting git remote"
  git remote set-url origin https://github.com/authelia/chartrepo.git
fi
